package cn.edu.dzkd.software.controller;

import cn.edu.dzkd.software.pojo.Role;
import cn.edu.dzkd.software.pojo.User;
import cn.edu.dzkd.software.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;  // spring框架自动生成了一个mapper对象，注入到此属性中

    @RequestMapping("/selectUsers")
    public Map<String, Object> selectUsers(@RequestParam int page, String username, String departmentName, String roleName) {
        return userService.selectUsers(page, username, departmentName, roleName);
    }

    @RequestMapping("/selectUserInformation")
    public Map<String, Object> selectUserInformation(@RequestParam String username) {
        return userService.selectUserInformation(username);
    }

    @RequestMapping("/delete")
    public Map<String, Object> deleteById(@RequestParam String id) {
        return userService.deleteById(id);
    }


    @RequestMapping("/insert")
    public Map<String, Object> insertUserJSON(@RequestBody User user) {
        return userService.insertUserJSON(user);
    }

    @RequestMapping("/update")
    public Map<String, Object> update(@RequestBody User user) {
        return userService.update(user);
    }

    @RequestMapping(value = "/updateInformation", method = RequestMethod.POST)
    public Map<String, Object> updateInformation(@RequestBody User user) {
        return userService.updateInformation(user);
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Map<String, Object> login(@RequestBody User user, HttpServletRequest request) {
        return userService.login(user, request);
    }
}
